# -*- coding: utf-8 -*-
from define import *
from api import deviceControl
from api import interface_config_handle
from api import add_ip_addr
import time
import os
try:
    os.remove('.\log\fw_1')
    os.remove('.\log\ADC')
    os.remove('.\log\Switch')
except:
    pass

dut_dc = deviceControl(dut['type'], dut['hostname'], dut['mgmt'])
router1_dc = deviceControl(router1['type'], router1['hostname'], router1['mgmt'], username = 'cisco', password ='cisco')
router2_dc = deviceControl(router2['type'], router2['hostname'], router2['mgmt'])
dut['controller'] = dut_dc
router1['controller'] = router1_dc
router2['controller'] = router2_dc

left_interface = 'physic'
right_interface = 'untag vlan'

#路由模式
print 'left interface: %s, right interface: %s'%(left_interface, right_interface)
 
#左侧接口配置
interface_config_handle(left_interface,
                        dut_dc,
                        dut_connect_desc[dut['hostname']]['left_interface'].split('-')[0],
                        vlan_left, 
                        trunk_id_left)
add_ip_addr(left_interface, 
            dut_dc, 
            dut_connect_desc[dut['hostname']]['left_interface'].split('-')[0], 
            vlan_left_dut_ip, mask,
            vlan_left_dut_ip6, prefix, 
            vlan_left, 
            trunk_id_left)
interface_config_handle(left_interface,
                        router1_dc,
                        dut_connect_desc[dut['hostname']]['left_interface'].split('-')[2],
                        vlan_left, 
                        trunk_id_left)
add_ip_addr(left_interface, 
            router1_dc, 
            dut_connect_desc[dut['hostname']]['left_interface'].split('-')[2], 
            vlan_left_router1_ip, mask,
            vlan_left_router1_ip6, prefix,
            vlan_left, 
            trunk_id_left)
#右侧接口配置
interface_config_handle(right_interface,
                        dut_dc,
                        dut_connect_desc[dut['hostname']]['right_interface'].split('-')[0],
                        vlan_right, 
                        trunk_id_right)
add_ip_addr(right_interface, 
            dut_dc, 
            dut_connect_desc[dut['hostname']]['right_interface'].split('-')[0], 
            vlan_right_dut_ip, mask,
            vlan_right_dut_ip6, prefix, 
            vlan_right, 
            trunk_id_right)
interface_config_handle(right_interface,
                        router2_dc,
                        dut_connect_desc[dut['hostname']]['right_interface'].split('-')[2],
                        vlan_right, 
                        trunk_id_right)
add_ip_addr(right_interface, 
            router2_dc, 
            dut_connect_desc[dut['hostname']]['right_interface'].split('-')[2], 
            vlan_right_router2_ip, mask,
            vlan_right_router2_ip6, prefix,
            vlan_right, 
            trunk_id_right)

#桥模式
#左侧接口配置
# interface_config_handle(left_interface,
#                         dut_dc,
#                         dut_connect_desc[dut['hostname']]['left_interface'].split('-')[0],
#                         vlan_bridge, 
#                         trunk_id_left)
# interface_config_handle(left_interface,
#                         router1_dc,
#                         dut_connect_desc[dut['hostname']]['left_interface'].split('-')[2],
#                         vlan_bridge, 
#                         trunk_id_left)
# #右侧接口配置
# interface_config_handle(right_interface,
#                         dut_dc,
#                         dut_connect_desc[dut['hostname']]['right_interface'].split('-')[0],
#                         vlan_bridge, 
#                         trunk_id_right)
# interface_config_handle(right_interface,
#                         router2_dc,
#                         dut_connect_desc[dut['hostname']]['right_interface'].split('-')[2],
#                         vlan_bridge, 
#                         trunk_id_right)
# print "ok"


dut_dc.exit()
router1_dc.exit()
router2_dc.exit()